package com.example.activititest.controller;

import java.util.List;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.engine.identity.UserQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.activititest.base.ResultDTO;
import com.example.activititest.utils.ResultUtils;

/**
 * 身份认证控制器
 *
 */
@RestController
@RequestMapping("incident")
public class ActivityIdentityController {
	@Autowired
	private IdentityService identityService;

	/**
	 * 获取组列表
	 * 
	 * @return
	 */
	@RequestMapping("/groups")
	public List<Group> groups() {
		List<Group> list = null;
		list = identityService.createGroupQuery().orderByGroupId().asc().list();
		ResultDTO dto = ResultUtils.getSuccess(list);
		return list;
	}

	/**
	 * 获取用户
	 * 
	 * @param groupId
	 * @return
	 */
	@RequestMapping("/users")
	public List<User> users(@RequestParam(value="groupId",required = false) String groupId) {
		List<User> list = null;
		UserQuery userQuery = identityService.createUserQuery();
		if (StringUtils.isNoneBlank(groupId)) {
			userQuery = userQuery.memberOfGroup(groupId);
		}
		list = userQuery.orderByUserId().asc().list();
		return list;
	}

}
